package com.sdp.irrigation.controller;


import java.time.LocalDateTime;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.sdp.core.bizc.db.Query;
import com.sdp.core.bizc.vo.DataCenter;
import com.sdp.core.bizc.vo.Result;
import com.sdp.irrigation.db.irrigation_as.service.IIrrigationAsService;
import com.sdp.irrigation.entity.IrrigationAs;

/**
 * <p>
 * 售后信息 前端控制器
 * </p>
 *
 * @author zsp
 * @since 2025-03-01
 */
@RestController
@RequestMapping("/IrrigationAsController")
public class IrrigationAsController {

	@Autowired
	private IIrrigationAsService iIrrigationAsService;
	
	@Autowired
	private Query query;

	@PostMapping(value = "/page")
	public Result<?> page(@RequestBody DataCenter dataCenter) {
		return Result.ok(query.page(iIrrigationAsService, IrrigationAs.class, dataCenter));
	}
	
	@PostMapping(value = "/list")
	public Result<?> list(@RequestBody DataCenter dataCenter) {
		return Result.ok(query.list(iIrrigationAsService, IrrigationAs.class, dataCenter));
	}
	
	@PostMapping(value = "/save")
	@Transactional(rollbackFor=Exception.class)
	public Result<?> save(@RequestBody IrrigationAs as) {
		if(as==null) {
			return Result.error("设备类型信息为空");
		}
		if(StringUtils.isEmpty(as.getKeyId())) {
			as.setCreateTime(LocalDateTime.now());
			as.setUpdateTime(LocalDateTime.now());
			iIrrigationAsService.save(as);
		}else {
			as.setUpdateTime(LocalDateTime.now());
			iIrrigationAsService.updateById(as);
		}
		return Result.ok();
	}
}

